package com.project.controller;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

@RestController
@RequestMapping("online")
public class OnlineController {

    @RequestMapping("showNumber")
    public String getNumber(HttpServletRequest request){
        HttpSession session = request.getSession();
        int x = 9/0;

        //从上下文中取出在线人数
        String info = request.getServletContext().getAttribute("number").toString();
        return "在线人数："+info;
    }

    @RequestMapping("destory")
    public String destroySession(HttpServletRequest request){
        //销毁会话
        request.getSession().invalidate();

        String info = request.getServletContext().getAttribute("number").toString();
        return "在线人数："+info;
    }
}
